package org.hsieh.tr.explore.ui.actions.dbview;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Event;
import org.hsieh.tr.explore.common.Refreshable;
import org.hsieh.tr.explore.util.JFaceUtil;

public class RefreshAction extends AbstractViewActionDelegate {

    private Refreshable refrehable;

    @Override
    public void selectionChanged(IAction action, ISelection selection) {
	refrehable = JFaceUtil.getFristSelected(selection, Refreshable.class);
    }

    @Override
    public void runWithEvent(IAction action, Event event) {
	if (refrehable != null) {
	    refrehable.refresh();
	    TreeViewer tree = (TreeViewer) getPart().getViewSite()
		    .getSelectionProvider();
	    tree.refresh(refrehable);
	}
    }
}
